﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Medecine.Interface.Converters
{
	/// <summary>
	/// Converter from <c>string[]</c> to <c>string</c>.
	/// </summary>
	public class StringArrayConverter : IValueConverter
	{
		/// <summary>
		/// Convert a string array to a string by concatenating the strings and separating them with a new line.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns></returns>
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null)
				return null;
			string[] stringArray = (string[])value;
			return String.Join(Environment.NewLine, stringArray);
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string str = (string)value;
			return str.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
		}
	}
}
